﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		SparkViewPage (generic).cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 // 
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion

using Dexter.Web.Mvc.ResourceCombiner;
using Dexter.Web.Mvc.ViewModel.ViewsData;
using Dexter.Web.Mvc.ViewsData;
using Dexter.Dependency;
using Dexter.Domain.Model;
using Dexter.Services;
using Dexter.Web.Utils;
using Spark.Web.Mvc;

namespace Dexter.Web.Mvc.ViewPages {
	/// <summary>
	/// 	Represents the properties and methods that are needed in order to render a view that uses Spark View Engine.
	/// </summary>
	/// <typeparam name = "TModel">The type of the model.</typeparam>
	public abstract class SparkViewPage <TModel> : SparkView <TModel> , IDexterView where TModel : class {
		ICombiner combiner;
		SiteConfiguration siteConfiguration;
		IUrlBuilder urlBuilder;
		IWebUtils utils;

		#region IDexterView Members

		/// <summary>
		/// 	Return the instance of <see cref = "IUrlBuilder" />.
		/// </summary>
		/// <value>The U.</value>
		public IUrlBuilder U {
			get { return urlBuilder; }
		}

		public SiteConfiguration C {
			get { return siteConfiguration; }
		}

		/// <summary>
		/// 	Gets the combiner.
		/// </summary>
		/// <value>The combiner.</value>
		public ICombiner Combiner {
			get { return combiner; }
		}

		/// <summary>
		/// Gets the utils.
		/// </summary>
		/// <value>The utils.</value>
		public IWebUtils Utils {
			get { return utils; }
		}

		/// <summary>
		/// Gets a value indicating whether this instance is moderator.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is moderator; otherwise, <c>false</c>.
		/// </value>
		public bool IsModerator {
			get { return base.Context.User.IsInRole ( "Moderator" ); }
		}

		/// <summary>
		/// 	Check if the specified username is the current logged user.
		/// </summary>
		/// <param name = "username">The username.</param>
		/// <returns></returns>
		public bool CurrentuserIsEqualtTo ( string username ) {
			return base.Context.User.Identity.Name == username;
		}

		#endregion

		/// <summary>
		/// 	Creates the helpers.
		/// </summary>
		protected override void CreateHelpers ( ) {
			base.CreateHelpers ( );

			var model = this.Model as PublicBaseViewData;
			
			if ( model != null ) {
				urlBuilder = model.UrlBuilder;
				siteConfiguration = model.Configuration;
				combiner = DexterContainer.Resolve <ICombiner> ( );
				utils = DexterContainer.Resolve<IWebUtils> ( );
			}
		}
	}
}
